#!/bin/bash

if [ $# -ne 5 ];
then
	echo The number of arguments is incorrect.
	exit 1
fi

MACH_ID=$1
FROM_DATE=$2
TO_DATE=$3
LIMIT_SIZE=$4
#URL=$5
URL1="http://ckj.ronghekj.cn/api/uploadLogs"
URL2="http://ckj.ronghekj.cn/api/uploadLogsNotFile"
FILE_SENT=0

for file in /userdata/*.mp4
do
	if [[ "$file" > "/userdata/$FROM_DATE" && "$file" < "/userdata/$TO_DATE" ]];
	then
		file_size=$(stat -c%s $file)
		if [[ file_size -lt $LIMIT_SIZE ]];
		then
			curl -X POST -F "id=$MACH_ID" -F "file=@$file" $URL1
			FILE_SENT=1
		fi
	fi
done

if [[ $FILE_SENT == 0 ]];
then
	curl -X POST -F "id=$MACH_ID" $URL2
fi
